package com.czh.springboot04.service.serviceimpl;

import com.czh.springboot04.entity.Coursetype;
import com.czh.springboot04.mapper.CoursetypeMapper;
import com.czh.springboot04.service.CoursetypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CoursetypeServiceImpl implements CoursetypeService {
    @Autowired
    private CoursetypeMapper coursetypeMapper;
    @Override
    public int addCourse(String coursetypename) {
        int i = coursetypeMapper.addCourse(coursetypename);
        return i;
    }

    @Override
    public int deleteCourse(int coursetypeid) {
        int i = coursetypeMapper.deleteCourse(coursetypeid);
        return i;
    }

    @Override
    public int updateCourse(Coursetype coursetype) {
        int i = coursetypeMapper.updateCourse(coursetype);
        return i;
    }

    @Override
    public List<Coursetype> findAllCourse() {
        List<Coursetype> coursetypes = coursetypeMapper.findAllCourse();
        return coursetypes ;
    }

    @Override
    public PageInfo<Coursetype> findAllCourse(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Coursetype> coursetypes = coursetypeMapper.findAllCourse();
        PageInfo<Coursetype> coursetypePageInfo = new PageInfo<>(coursetypes);
        return coursetypePageInfo;
    }

    @Override
    public PageInfo<Coursetype> findCourseById(int coursetypeid, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Coursetype> courseById = coursetypeMapper.findCourseById(coursetypeid);
        PageInfo<Coursetype> coursetypePageInfo = new PageInfo<>(courseById);
        return coursetypePageInfo;
    }


}
